from .base import Base
from .engine import db
from .types import StringUUID
from sqlalchemy import func, ForeignKey
from sqlalchemy.orm import relationship

# Minimal placeholder for App model
class App(Base):
    __tablename__ = "apps"
    __table_args__ = (db.PrimaryKeyConstraint("id", name="app_pkey"),)
    id = db.Column(StringUUID, server_default=db.text("uuid_generate_v4()"))
    name = db.Column(db.String(255), nullable=False)
    # Add other fields as necessary, for now keep minimal
    created_at = db.Column(db.DateTime, nullable=False, server_default=func.current_timestamp())

# Minimal placeholder for Tag model
class Tag(Base):
    __tablename__ = "tags"
    __table_args__ = (db.PrimaryKeyConstraint("id", name="tag_pkey"),)
    id = db.Column(StringUUID, server_default=db.text("uuid_generate_v4()"))
    name = db.Column(db.String(255), nullable=False)
    type = db.Column(db.String(50), nullable=False) # e.g., "knowledge", "document"
    # tenant_id = db.Column(StringUUID, nullable=False) # Removed for standalone simplicity
    created_at = db.Column(db.DateTime, nullable=False, server_default=func.current_timestamp())

# Minimal placeholder for TagBinding model
class TagBinding(Base):
    __tablename__ = "tag_bindings"
    __table_args__ = (db.PrimaryKeyConstraint("id", name="tag_binding_pkey"),
                      db.Index("tag_binding_target_idx", "target_id", "tag_id"))
    id = db.Column(StringUUID, server_default=db.text("uuid_generate_v4()"))
    tag_id = db.Column(StringUUID, ForeignKey("tags.id"), nullable=False)
    target_id = db.Column(StringUUID, nullable=False) # ID of the item being tagged (e.g., dataset_id, document_id)
    # tenant_id = db.Column(StringUUID, nullable=False) # Removed for standalone simplicity
    created_at = db.Column(db.DateTime, nullable=False, server_default=func.current_timestamp())

    tag = relationship("Tag")

# Minimal placeholder for UploadFile model
class UploadFile(Base):
    __tablename__ = "upload_files"
    __table_args__ = (db.PrimaryKeyConstraint("id", name="upload_file_pkey"),)
    id = db.Column(StringUUID, server_default=db.text("uuid_generate_v4()"))
    # tenant_id = db.Column(StringUUID, nullable=False) # Removed for standalone
    # user_id = db.Column(StringUUID, nullable=False) # Created_by might be enough
    name = db.Column(db.String(255), nullable=False)
    extension = db.Column(db.String(50), nullable=True)
    size = db.Column(db.Integer, nullable=True)
    mime_type = db.Column(db.String(255), nullable=True)
    # For standalone, file_key might be a path to local storage
    file_key = db.Column(db.Text, nullable=True) # Path or key in a simple storage
    created_by = db.Column(StringUUID, nullable=True) # User who uploaded
    created_at = db.Column(db.DateTime, nullable=False, server_default=func.current_timestamp())

    # If you need to store the actual file content in DB (not recommended for large files):
    # content = db.Column(db.LargeBinary, nullable=True)

